//
//  MYBaseController.m
//  MYChatting
//
//  Created by mac on 16/7/15.
//  Copyright © 2016年 lhf. All rights reserved.
//

#import "MYBaseController.h"
#import "VisitorLoginView.h"
#import "MYOAuthController.h"
#import "UserInfo.h"


@interface MYBaseController ()<VisitorLoginViewDelegate>



@property (nonatomic,assign) BOOL userLogin ;


@end

@implementation MYBaseController


#warning oc中单继承 多继承的问题

- (void)loadView{
    UserInfo *userInfo = [[[UserInfo alloc] init] loadUserInfo];
    self.userLogin = (userInfo.access_token ? YES : NO);
    
    if ((self.userLogin)) {
        //展示tableView
        [super loadView];
    }else{
        VisitorLoginView *visitorLoginView = [[VisitorLoginView alloc] init];
        
#warning 这个对公有属性的赋值是必须的，否则，子类相应的方法不能实现
        self.visitorLoginView = visitorLoginView;
        
        visitorLoginView.delegate = self;
        self.view = visitorLoginView;
       
        self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"注册" style:UIBarButtonItemStylePlain target:self action:@selector(userWillRegister)];
        self.navigationItem.rightBarButtonItem.tintColor = [UIColor orangeColor];
        
        self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"登陆" style:UIBarButtonItemStylePlain target:self action:@selector(userWillLogin)];
        self.navigationItem.leftBarButtonItem.tintColor = [UIColor orangeColor];
    }
  
}


#pragma mark VisitorLoginViewDelegate的代理方法
- (void)userWillLogin{
    
#warning OAuth授权开始
    
    MYOAuthController *oauthController = [[MYOAuthController alloc] init];
    UINavigationController *oauthNav = [[UINavigationController alloc] initWithRootViewController:oauthController];
    [self presentViewController:oauthNav animated:YES completion:nil];
}


- (void)userWillRegister{
    NSLog(@"userWillRegister");
}



- (void)viewDidLoad {
    [super viewDidLoad];
    
   
}



@end
